package hadoop.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HdfsClient {
    FileSystem fs;

    @Before
    public void testBefore() throws URISyntaxException, IOException, InterruptedException {
        // 1 获取文件系统
        Configuration configuration = new Configuration();
        configuration.set("dfs.replication", "2");

        fs = FileSystem.get(new URI("hdfs://hadoop103:8020"), configuration, "atguigu");
    }

    @Test
    public void test1() throws IOException {

        // 2 上传文件
        fs.copyFromLocalFile(new Path("C:\\SoftwareLife\\PPTTemplate\\王金根.pptx"), new Path("/小王.pptx"));

    }

    @After
    public void testAfter() throws IOException {
        // 3 关闭资源
        fs.close();
    }

}
